﻿@{
    @using Microsoft.AspNetCore.Localization;
    @using Microsoft.Extensions.Localization;
    @using System.Globalization;

    IStringLocalizer SR = ViewBag.SR as IStringLocalizer;
    IRequestCultureFeature requestCultureFeature = ViewBag.requestCultureFeature as IRequestCultureFeature;
    RequestCulture requestCulture = ViewBag.requestCulture as RequestCulture;

    ViewData["Title"] = SR["Request Localization"];
}

<style>
</style>
@section Scripts{
    <script>
        function useCookie() {
            var culture = document.getElementById('culture');
            var uiCulture = document.getElementById('uiCulture');
            var cookieValue = '@(CookieRequestCultureProvider.DefaultCookieName)' + culture.options[culture.selectedIndex].value + '|uic=' + uiCulture.options[uiCulture.selectedIndex].value;
            document.cookie = cookieValue;
            window.location = window.location.href.split('?')[0];
        }

        function clearCookie() {
            document.cookie = '@(CookieRequestCultureProvider.DefaultCookieName)=""';
        }
    </script>
}
<h1>@(SR["Request Localization Sample"])</h1>
<h1>@(SR["Hello"])</h1>

<form id="theForm" method="get">
    <div class="form-group" style="width: 300px;margin-bottom:1rem;">
        <label for="culture">@SR["Culture"]: </label>
        <select id="culture" name="culture" class="form-control">
            <option value="">-- select --</option>
            <option value="@(new CultureInfo("en-US").Name)">@(new CultureInfo("en-US").DisplayName)</option>
            <option value="@(new CultureInfo("fr-FR").Name)">@(new CultureInfo("fr-FR").DisplayName)</option>
            <option value="@(new CultureInfo("ja-JP").Name)">@(new CultureInfo("ja-JP").DisplayName)</option>
            <option value="@(new CultureInfo("zh-CN").Name)">@(new CultureInfo("zh-CN").DisplayName)</option>
        </select>
    </div>
    <div class="form-group" style="width: 300px;margin-bottom: 1rem;">
        <label for="uiCulture">@SR["UI Culture"]: </label>
        <select id="uiCulture" name="ui-culture" class="form-control">
            <option value="">-- select --</option>
            <option value="@(new CultureInfo("en-US").Name)">@(new CultureInfo("en-US").DisplayName)</option>
            <option value="@(new CultureInfo("fr-FR").Name)">@(new CultureInfo("fr-FR").DisplayName)</option>
            <option value="@(new CultureInfo("ja-JP").Name)">@(new CultureInfo("ja-JP").DisplayName)</option>
            <option value="@(new CultureInfo("zh-CN").Name)">@(new CultureInfo("zh-CN").DisplayName)</option>
        </select>
    </div>
    <div class="form-group margin-top-xs" style="width: 300px;margin-bottom: 1rem;">
        <input type="submit" value="go QS" class="btn btn-primary" />
        <input type="button" value="go cookie" onclick="useCookie();" class="btn btn-danger" />
        <a href="/Culture" onclick="clearCookie();">@SR["reset"]</a>
    </div>
</form>
<table class="table">
    <tbody>
        <tr>
            <th>Winning provider:</th>
            <td>@requestCultureFeature.Provider.GetType().Name</td>
        </tr>
        <tr>
            <th>@SR["Current request culture:"]</th>
            <td>@requestCulture.Culture.DisplayName (@requestCulture.Culture)</td>
        </tr>
        <tr>
            <th>@SR["Current request UI culture:"]</th>
            <td>@requestCulture.UICulture.DisplayName (@requestCulture.UICulture)</td>
        </tr>
        <tr>
            <th>@SR["Current thread culture:"]</th>
            <td>@CultureInfo.CurrentCulture.DisplayName (@CultureInfo.CurrentCulture)</td>
        </tr>
        <tr>
            <th>@SR["Current thread UI culture:"]:</th>
            <td>@CultureInfo.CurrentUICulture.DisplayName (@CultureInfo.CurrentUICulture)</td>
        </tr>
        <tr>
            <th>@SR["Current date (invariant full):"]:</th>
            <td>@DateTime.Now.ToString("F", CultureInfo.InvariantCulture)</td>
        </tr>
        <tr>
            <th>@SR["Current date (invariant):"]</th>
            <td>@DateTime.Now.ToString(CultureInfo.InvariantCulture)</td>
        </tr>
        <tr>
            <th>@SR["Current date (request full):"]</th>
            <td>@DateTime.Now.ToString("F")</td>
        </tr>
        <tr>
            <th>@SR["Current date (request):"]</th>
            <td>@DateTime.Now.ToString()</td>
        </tr>
        <tr>
            <th>@SR["Current time (invariant):"]</th>
            <td>@DateTime.Now.ToString("T", CultureInfo.InvariantCulture)</td>
        </tr>
        <tr>
            <th>@SR["Current time (request):"]</th>
            <td>@DateTime.Now.ToString("T")</td>
        </tr>
        <tr>
            <th>@SR["Big number (invariant):"]</th>
            <td>@((Math.Pow(2, 42) + 0.42).ToString("N", CultureInfo.InvariantCulture)))</td>
        </tr>
        <tr>
            <th>@SR["Big number (request):"]</th>
            <td>@((Math.Pow(2, 42) + 0.42).ToString("N")))</td>
        </tr>
        <tr>
            <th>@SR["Big number negative (invariant):"]</th>
            <td>-@(((Math.Pow(2, 42) + 0.42).ToString("N", CultureInfo.InvariantCulture)))</td>
        </tr>
        <tr>
            <th>@SR["Big number negative (request):"]</th>
            <td>-@((Math.Pow(2, 42) + 0.42).ToString("N")))</td>
        </tr>
        <tr>
            <th>@SR["Money (invariant):"]</th>
            <td>@((2199.50.ToString("C", CultureInfo.InvariantCulture)))</td>
        </tr>
        <tr>
            <th>@SR["Money (request):"]</th>
            <td>@(2199.50.ToString("C"))</td>
        </tr>
        <tr>
            <th>@SR["Money negative (invariant):"]</th>
            <td>@((-2199.50).ToString("C", CultureInfo.InvariantCulture))</td>
        </tr>
        <tr>
            <th>@SR["Money negative (request):"]</th>
            <td>@((-2199.50).ToString("C"))</td>
        </tr>
    </tbody>
</table>
